package com.blast.cn.persenter.check

import android.content.Intent
import android.os.Environment
import android.os.StatFs
import com.wxl.common.AppConstant
import com.wxl.common.base.WorkPresenter
import com.wxl.common.util.ObservableUtil
import com.wxl.common.wiget.TipPop
import io.reactivex.functions.Action
import kotlinx.android.synthetic.main.activity_check_device_layout.view.*

class CheckDeviceStoragePresenter : WorkPresenter() {

    override fun onStartDoWork(vararg args: Any) {
        rootView.checkProgressSub.text = "正在检查设备存储,请勿进行其他操作..."
        val statFs = StatFs(Environment.getExternalStorageDirectory().path)
        val availableSize = statFs.availableBytes
        if(availableSize < AppConstant.mStorageSize){
            TipPop.showSure(rootView.context,"自检失败！\n 内存空间不足，请及时清理。", Action {
                val intent =  Intent(Intent.ACTION_GET_CONTENT)
                intent.setType("*/*")//设置类型，我这里是任意类型，任意后缀的可以这样写。
                intent.addCategory(Intent.CATEGORY_OPENABLE)
                rootView.context.startActivity(intent)
            })
        } else {
            ObservableUtil.delay(300, Runnable {
                rootView.checkProgressBar.progress = 50
                rootView.checkProgressText.text = "50%"
                doNext()
            })
        }
    }
}